package com.ext.detwo.controller;

import com.ext.detwo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class test1Controller {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/get1")
    public String get1() {
        String url = "http://localhost:9025/get1";
        String res1 = restTemplate.getForObject(url, String.class);
        log.info("getForObject======" + res1);
        return "22";
    }

    @GetMapping("/get2")
    public String get2() {
        String url = "http://localhost:9025/get2/{msg}";
        Map<String,Object>map  = new HashMap<>();
        map.put("msg","good");
        String res1 = restTemplate.getForObject(url, String.class,map);
        log.info("getForObject======" + res1);
        return res1;
    }

    @GetMapping("/get4")
    public String get4() {
        String url = "http://localhost:9025/get2/good";
        String res1 = restTemplate.getForObject(url, String.class);
        log.info("get4======" + res1);
        log.info("---------");
        log.info("---------");
        return res1;
    }


    @GetMapping("/get3")
    public String  get3(){
        String good = "good";
        String url = "http://localhost:9025/get3?msg="+good;
        String res1 = restTemplate.getForObject(url, String.class);
        log.info("getForObject===2222" + res1);
        return res1;
    }

    @GetMapping("/get5")
    public String get5(){
        User user = new User();
        user.setId(1);
        user.setName("name");
        String url = "http://localhost:9025/get4";
        String res1 = restTemplate.postForObject(url,user, String.class);
        return res1;
    }

    @GetMapping("/get6")
    public  String  get6(){
        log.info("good-----------------");
        return "good";
    }

}
